package tianxing

import (
	"encoding/json"
	ms "gin_template/core/request"
	"strings"

	"go.uber.org/zap"
)

type StarResult struct {
	Common
	Newslist []StarValue `json:"newslist"`
}

type StarValue struct {
	Value
	Type string `json:"type"`
}

func RequestStar(config interface{}, astro string) string {
	conf := config.(*Config)
	option := `astro=` + astro
	result := &StarResult{}
	res := ms.RequestPost(conf.Url+"/star/index?key="+conf.Key, option)
	err := json.Unmarshal(res, &result)
	if err != nil {
		zap.L().Info("RequestStar序列化失败", zap.Error(err))
	}
	if result.Code == 150 {
		return "今天星座机器人卡壳啦，请充值让我修复它吧，hhh"
	}

	var info []string
	for _, content := range result.Newslist {
		info = append(info, content.Type+" : "+content.Content)
	}
	//fmt.Println("======info======", strings.Join(info, ","))
	return strings.Join(info, "，")
}
